const app = getApp()
Page({
  data: {
    themeVal: app.globalData.theme,
    themeBgObj: {
      themeA: '#ffeb0c',
      themeB: '#ff4500'
    },
    userInfo: {},
    Permission: app.globalData.token ? true : false,
    shopper: false
  },
  onLoad: function (options) {

  },
  onShow: function () {
    this.getUserRole()
    this.setData({
      Permission: app.globalData.token ? true : false
    })
    app.Store.set("enterType", 'init')
  },
  onPullDownRefresh: function () {

  },
  toWaiting(e) {
    let name = e.currentTarget.dataset.name;
    app.WxService.navigateTo(`/pages/expecting/index`, { title: decodeURIComponent(name) })
  },
  toPage(e) {
    let index = e.currentTarget.dataset.tab;
    if (index == 1) {
      app.WxService.navigateTo('/pages/my-shop/index')
    } else if (index == 2) {
      app.WxService.reLaunch(`/pages/order/index/index`, { type: 'user' })
      app.Store.set("enterType", 'user')
    } else if (index == 3) {
      app.WxService.navigateTo(`/pages/supply/index`)
    } else if (index == 4) {
      app.Store.set('buyOrderType', 'supply')
      app.WxService.navigateTo(`/pages/shop/index/index`, { enter: 'user' })
    } else if (index == 5) {
      app.WxService.reLaunch(`/pages/order/index/index`, { type: 'supply' })
      app.Store.set("enterType", 'supply')

    } else if (index == 6) {
      app.WxService.navigateTo(`/pages/address/index`)

    } else if (index == 7) {
      app.WxService.navigateTo(`/pages/openShop/index`)

    } else if (index == 8) {
      app.WxService.navigateTo(`/pages/feedback/index`)
    } else if (index == 9) {
      app.WxService.navigateTo(`/pages/about-us/index`)

    }
  },
  getUserRole() {
    let user = app.Store.get('user')
    if (user) {
      this.setData({
        userInfo: {
          avatarUrl: user.avatarUrl,
          nickName: user.nickName
        },
        shopper: user.userRole == 1 ? false : true
      })
    }
  },
  loginOut(){
    let _this=this
    wx.showModal({
      title: '温馨提示',
      content: '确定要退出吗？',
      success(res) {
        if (res.confirm) {
          wx.clearStorage()
          _this.setData({
            userInfo: {},
            Permission: false
          })
        } 
      }
    })
   
  },
  changeData(data) {
    this.getUserRole()
  }
})